/*
 * @Author: ykp 501436989@qq.com
 * @Date: 2025-05-07 14:12:55
 * @LastEditors: ykp 501436989@qq.com
 * @LastEditTime: 2025-05-21 09:51:03
 * @FilePath: \vue-ts\src\views\todolist\init.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { urgencyList, taskCategory, taskStatus } from './gojson'
import {
    initDB,
    querylist,
    queryDetails,
    addItem,
} from "./indexeddbOperations";
// import draggable from "vuedraggable";
  import { useCounterStore } from '../stores/counter'
//获取值
let isInit = localStorage.getItem('isInit')
if (!isInit) {
    const listUp = async function () {
        await initDB();
        await addItem({
            executor: "20",
            id: "oz9n9GFpQWWFv0IBThUUNYW7dV0gatCA",
            importance: '0',
            manDay: "10",
            packetType: "0",
            progress: null,
            starTime: "2025-05-01",
            summary: "11111111",
            time: "2025-05-31",
            title: "测试任务",
            type: 'eiWV6qfacoLIahIXxLRTh4WSmM0VIVBt'
        })
        for (let item of urgencyList) {
            const request = indexedDB.open('myDatabase', 1);
            // 数据库打开成功时触发
            request.onsuccess = await function (event: any) {
                const db = event.target.result as IDBDatabase;
                // 开始一个读写事务
                const transaction = db.transaction(['urgencyList'], 'readwrite');
                const objectStore = transaction.objectStore('urgencyList');
                // 要更新的数据
                const updatedData = item;
                // 使用 put() 方法更新数据
                const updateRequest = objectStore.put(updatedData);

            };
        }


        for (let item of taskCategory) {
            const request = indexedDB.open('myDatabase', 1);
            // 数据库打开成功时触发
            request.onsuccess = await function (event: any) {
                const db = event.target.result;
                // 开始一个读写事务
                const transaction = db.transaction(['taskCategory'], 'readwrite');
                const objectStore = transaction.objectStore('taskCategory');
                // 要更新的数据
                const updatedData = item;
                // 使用 put() 方法更新数据
                const updateRequest = objectStore.put(updatedData);

            };
        }

        for (let item of taskStatus) {
            const request = indexedDB.open('myDatabase', 1);
            // 数据库打开成功时触发
            request.onsuccess = await function (event: any) {
                const db = event.target.result;
                // 开始一个读写事务
                const transaction = db.transaction(['taskStatus'], 'readwrite');
                const objectStore = transaction.objectStore('taskStatus');
                // 要更新的数据
                const updatedData = item;
                // 使用 put() 方法更新数据
                const updateRequest = objectStore.put(updatedData);

            };
        }

    };
    listUp()
    localStorage.setItem('isInit', '1')
}